package com.peng.crm.workbench.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.peng.crm.settings.entity.DicValue;
import com.peng.crm.workbench.dao.ActivityDao;
import com.peng.crm.workbench.entity.Activity;
import com.peng.crm.workbench.service.ActivityService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 市场活动表(Activity)表服务实现类
 *
 * @author makejava
 * @since 2022-07-02 19:11:34
 */
@Service("activityService")
public class ActivityServiceImpl implements ActivityService {
    @Resource
    private ActivityDao activityDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Activity queryById(String id) {
        return this.activityDao.queryById(id);
    }

    /**
     * 查询所有数据
     * @return
     */
    @Override
    public List<Activity> list() {
        return activityDao.list();
    }

    /**
     * 分页查询
     *
     * @param pageNumber    页码
     * @param pageSize      条数
     * @return 查询结果
     */
    @Override
    public Map<String, Object> listPage(Integer pageNumber, Integer pageSize, Activity activity) {
        PageHelper.startPage(pageNumber,pageSize);
        PageInfo<DicValue> pageInfo = new PageInfo(activityDao.select(activity));
        Map<String, Object> pageMap = new HashMap<>();
        pageMap.put("list",pageInfo.getList());
        pageMap.put("total",pageInfo.getTotal());
        return pageMap;
    }

    /**
     * 新增数据
     *
     * @param activity 实例对象
     * @return 实例对象
     */
    @Override
    public Boolean insert(Activity activity) {
        return activityDao.insert(activity)>0;
    }

    /**
     * 修改数据
     *
     * @param activity 实例对象
     * @return 实例对象
     */
    @Override
    public Activity update(Activity activity) {
        this.activityDao.update(activity);
        return this.queryById(activity.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.activityDao.deleteById(id) > 0;
    }

    /**
     * 删除多条数据
     * @param ids   主键数组
     * @return
     */
    @Override
    public boolean removeBatch(String[] ids) {
        return activityDao.deletes(ids);
    }
}
